import { useDispatch } from "./useStore"
import Taro from "@tarojs/taro"

const toast = (option:object = {})=>{
    useDispatch('setToast',option).then(()=>{});
}

export const text = (msg:string = 'test')=>{
    toast({ msg, type: 'text', show: true,duration:2000})
}

export const success = (msg:string = 'ok')=>{
    toast({ msg, type: 'success', show: true,duration:2000})
}

export const error = (msg:string = 'fail')=>{
    toast({ msg, type: 'fail', show: true,duration:2000})
}

export const warn = (msg:string = 'warn')=>{
    toast({ msg, type: 'warn', show: true,duration:2000})
}

export const loading = (title:string = '加载中')=>{
    Taro.showLoading({title});
}

export const hide = ()=>{
    Taro.hideLoading();
}


export default {
    text,success,error,warn,loading,hide
}

